/**  
 * GalleryAdapter.java
 * @version 1.0
 * @author Haven
 * @createTime 2011-12-9 涓嬪崍05:04:34
 */
package com.etong.citymap.adapter;

import java.util.ArrayList;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;

import com.etong.citymap.db.util.CityApplication;
import com.etong.citymap.view.MyImageView;

public class GalleryAdapter extends BaseAdapter {

	private Context context;
	private Bitmap images[] ;
	private CityApplication cityApplication;

	public GalleryAdapter(Context context,Application application) {
		this.context = context;
		cityApplication = (CityApplication)application;
		ArrayList<Bitmap> bitmaps=new ArrayList<Bitmap>();
		if(cityApplication.getImageListPosttion()==0){
			for(int i=0;i<cityApplication.getImageList().length;i++){
					bitmaps.add(cityApplication.getImageList()[i].getBitmap());
			
			}
		}else if(cityApplication.getImageListPosttion()==1){
			for(int i=0;i<cityApplication.getImageList_Net().length;i++){
					bitmaps.add(cityApplication.getImageList_Net()[i].getBitmap());
			}
		}
		
		images=new Bitmap[bitmaps.size()];
		for(int i=0;i<images.length;i++){
			images[i]=bitmaps.get(i);
		}
		
	}

	@Override
	public int getCount() {
		return images.length;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Bitmap bmp = images[position];
		MyImageView view = new MyImageView(context, bmp.getWidth(), bmp.getHeight());
		view.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		view.setImageBitmap(bmp);
		return view;
	}

}
